#include "CNet.h"

IRequest* NewRequest(IConnect* connect,Data* data){
    Request* request=(Request*)malloc(sizeof(Request));
    request->connection=connect;
    request->data=data;
    // 手动实现接口
    request->vtable.GetConnection=RequestGetConnection;
    request->vtable.GetData=RequestGetData;

    return (IRequest*)request;
}


IConnect* RequestGetConnection(IRequest* self){
    Request* request=(Request*)self;
    return request->connection;
}
Data* RequestGetData(IRequest* self){
    Request* request=(Request*)self;
    return request->data;
}

// 这个函数用来处理一个请求，根据request的路由来开启一个线程来处理这些内容
void RequestHandle(IRequest* self){
    Request* request=(Request*)self;
    Connection* connection=(Connection*)request->connection;
    connection->router->BeforeHandle(self);
    connection->router->Handle(self);
    connection->router->AfterHandle(self);
}